import {http} from "@/utils/http/axios";
import {storage} from '@/utils/Storage';

export function saveOauth(name, collect, rest, mark) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth',
    headers: {token: storage.get('token')},
    method: 'POST',
    params: {
      name: name,
      rest: rest,
      mark: mark,
      collect: collect,
    },
  });
}

export function deleteOauth(id) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth?id=' + id,
    headers: {token: storage.get('token')},
    method: 'DELETE',
    params: {
      id: id,
    },
  });
}

export function updateOauth(id, name, collect, rest, mark, status) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth',
    headers: {token: storage.get('token')},
    method: 'PUT',
    params: {
      id: id,
      name: name,
      rest: rest,
      mark: mark,
      collect: collect,
      status: status,
    },
  });
}

export function oauthPage(params) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth/page',
    headers: {token: storage.get('token')},
    method: 'POST',
    params,
  });
}

// 角色权限id集合
export function roleOauthIds(id) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth/role/ids?id=' + id,
    headers: {token: storage.get('token')},
    method: 'GET',
  });
}

/**
 * 权限树
 */
export function oauthTree() {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/oauth/tree',
    headers: {token: storage.get('token')},
    method: 'GET',
  });
}
